<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<jsp:include page="../commons/top.jsp" />
<style type="text/css">
	select{outline:none;}
	select option{cursor:pointer;padding:4px;padding-left: 15px;}
</style>
<script type="text/javascript">
	// 移动到右边
	function to_right(){
		var emp_no = $("#empNo").val();
		$("#account_from").find("option:selected").each(function(i,obj){
			emp_no += $(obj).val() + ",";
			$("#account_to").append("<option value='"+$(obj).val()+"'>"+$(obj).text()+"</option>");
			$(obj).remove();
		});
		$("#empNo").val(emp_no);
	}
	// 移动到右边
	function to_left(){
		$("#account_to").find("option:selected").each(function(i,obj){
			$("#account_from").append("<option value='"+$(obj).val()+"'>"+$(obj).text()+"</option>");
			$(obj).remove();
		});
		var emp_no = "";
		$("#account_to").find("option").each(function(i,obj){
			emp_no += $(obj).val() + ",";
		});
		$("#empNo").val(emp_no);
	}
	// 保存
	function saveAddress(){
		
		 $.ajax({
	     type: "post",
	     url: "<c:url value="/report/email/saveAddress"/>",
	     data: {reportType:$("#reportType").val(), empNo:$("#empNo").val()},
	     dataType: "json",
	     success: function(data){
	    	 if(data.result == "success"){
	    		 alert("<spring:message code="msg.save.success"></spring:message>");
	    	 }
	    	 else{
	    		 alert("<spring:message code="msg.save.fail"></spring:message>");
	    	 }
	     }
		 });
	}
	// 查询
	function reportSearch(){
		
		$("#searchForm").attr("action","<c:url value="/report/email/setAddress" />");
		$("#searchForm").submit();
	}
	// 重置
	function reportReset() {
		
		window.location.href = "<c:url value="/report/email/setAddress" />";
	}
</script>
<div id="breadCrumbDiv">
	<span class="main_title"><a href="main.html">首页</a></span>
	<span class="main_title"><a href="#">E-Report</a></span>
	<span class="main_title"><a href="#">收件人管理</a></span>
</div>
<div id="workAreaDiv">
	<div id="organizationListDiv">
		<input type="hidden" id="reportId" name="reportId" value="${reportInfo.id}"/>
		<input type="hidden" id="empNo" name="empNo" value="${defaultValue}"/>
		<form id="searchForm" action="" method="post">
		<table border="0" cellpadding="0" cellspacing="0" width="100%" class=""> 
	    <tr> 
	    	<td class="table_title">查询</td> 
	    </tr> 
	    <tr> 
      	<td> 
      		<table width="100%" cellpadding="1" cellspacing="1" border="0" class="table_border"> 
          	<tr class="table_display_1"> 
              <td width="5%" class="table_display_2">报表名称</td> 
              <td width="10%">
              	<select id="reportType" name="reportType">
              		<option value="">----</option>
            			<option value="YSD00001" 
            				<c:if test="${param.reportType eq 'YSD00001'}">selected</c:if>
            			>销售日报表</option>
            			<option value="YSW00001"
            				<c:if test="${param.reportType eq 'YSW00001'}">selected</c:if>
            			>销售周报表</option>
            			<option value="YSM00001"
            				<c:if test="${param.reportType eq 'YSM00001'}">selected</c:if>
            			>销售月报表</option>
              	</select>
              </td> 
           	</tr> 
           </table>
        </td> 
      </tr> 
      <tr align="right" class="btnTR"> 
	      <td> 
	      	<input type="button" onclick="reportSearch()" 
	      		value="<spring:message code="button.search"></spring:message>">&nbsp;
		      <input type="button" onclick="reportReset()" 
		      	value="<spring:message code="button.reset"></spring:message>"/> 
	      </td> 
    	</tr>
    </table>
    </form> 
    <br/> 
		<table border="0" cellpadding="0" cellspacing="0" width="100%" class=""> 
      <tr> 
	    	<td class="table_title">收件人姓名</td> 
	    </tr> 
    	<tr> 
	      <td> 
	      	<table width="100%" cellpadding="1" cellspacing="1" border="0" class="table_border"> 
          	<tr class="table_display_1">
          		<td width="40%" class="table_display_2">可选人员</td>
          		<td width="20%" class="table_display_2"></td>
          		<td width="40%" class="table_display_2">已选人员</td>
          	</tr>
          	<tr class="table_display_1">
          		<td align="center">
          			<select id="account_from" multiple style="width:300px;height:350px;">
									<c:forEach items="${newList}" var="account">
										<option value="${account.empNo}">${account.empName}</option>
									</c:forEach>
				        </select>
          		</td>
          		<td align="center">
          			<input type="button" onclick="to_right()" value="==>"/>
          			<br><br><br><br>
          			<input type="button" onclick="to_left()" value="<=="/>
          		</td>
          		<td align="center">
          			<select id="account_to" multiple style="width:300px;height:350px;">
									<c:forEach items="${oldList}" var="account">
										<option value="${account.empNo}">${account.empName}</option>
									</c:forEach>
				        </select>
          		</td>
          	</tr>
          </table>
	      </td> 
    	</tr>
    	<tr align="center" class="btnTR"> 
	      <td> 
	      	<input type="button" onclick="saveAddress()" 
	      		value="<spring:message code="button.save"></spring:message>">
	      </td> 
    	</tr>
    </table>
	</div>
</div>
<jsp:include page="../commons/bottom.jsp" />